package com.thenmoret.admin.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.thenmoret.constast.Constast;
import com.thenmoret.pojo.Admin;
import com.thenmoret.service.AdminService;

@RequestMapping("/")
@Controller
public class AdminController {

	@Autowired
	private AdminService adminService;
	
	@RequestMapping("/index")
	public String loginUI()
	{
		return "/login";
	}
	
	@RequestMapping(value="login",method=RequestMethod.POST)
	public String login(Admin admin,HttpServletRequest request)
	{
		Admin ad = adminService.getAdmin(admin);
		if(ad!=null)
		{
			HttpSession session = request.getSession();
			session.setAttribute(Constast.LOGIN_RESULT, Constast.LOGIN_SUCCESS);
			return "/admin/main";
		}
		else
		{
			return "/login";
		}
		
	}
}
